﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using ZX.OA.Model;

namespace ZX.OA.DAL
{
    public class StationeryInfoDal
    {
        Entity entity = new Entity();
        /// <summary>
        /// 办公用品的申领记录
        /// </summary>
        /// <returns></returns>
        public List<StationeryInfo> GetStationery()
        {
            return entity.StationeryInfo.ToList();
        }
        /// <summary>
        /// 添加工作任务
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int StationeryInfoAdd(StationeryInfo t)
        {
            entity.StationeryInfo.Add(t);
            return entity.SaveChanges();
        }
        /// <summary>
        /// 办公用品的删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleStationery(int id)
        {
            entity.StationeryInfo.Remove(entity.StationeryInfo.Find(id));
            return entity.SaveChanges();
        }
        /// <summary>
        /// 根据办公用品编号获取办公用品信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public StationeryInfo GetStationeryId(int id)
        {
            return entity.StationeryInfo.Find(id);
        }
        /// <summary>
        /// 修改办公用品信息
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int StationeryUpdate(StationeryInfo s)
        {
            entity.Entry(s).State = System.Data.EntityState.Modified;
            return entity.SaveChanges();
        }

        /// <summary>
        /// 根据办公用品编号或办公用品名称查询办公用品信息
        /// </summary>
        /// <param name="ProjectName"></param>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        public List<StationeryInfo> SrachProject(string StationeryName, int? StationeryId)
        {
            return entity.StationeryInfo.Where((p => (string.IsNullOrEmpty(StationeryName) ? true : p.SationeryName.Contains(StationeryName)) || (p.SationeryId == null ? true : p.SationeryId == StationeryId))).ToList();

        }
    }
}